#ifndef FRAMEWORK_SINGLETON_IMP_H
#define FRAMEWORK_SINGLETON_IMP_H

#include "singleton.h"

template <typename T>
T& project_w_framework::Singleton<T>::Instance() {
	if (!si_singleton)
	{
		// TODO: LOCK

		if (!si_singleton)
		{
			if (si_destoryed)
			{
				si_destoryed = false;
			}

			si_singleton = new T();
		}
	}

	return *si_singleton;
}

template <typename T>
void project_w_framework::Singleton<T>::DestorySingleton()
{
	if (si_singleton)
	{
		delete si_singleton;
	}

	si_singleton = NULL;
	si_destoryed = true;
}

#define INSTANTIATE_SINGLETON_1(TYPE) \
    template class project_w_framework::Singleton<TYPE>; \
    template<> TYPE* project_w_framework::Singleton<TYPE>::si_singleton = 0; \
    template<> bool project_w_framework::Singleton<TYPE>::si_destoryed = false


#endif
